from common.db import models
from django.contrib.postgres.fields import JSONField


# Create your models here.


class PublicFile(models.Model):
    """
    公开文件
    """

    name = models.CharField("名字", blank=True, null=True)
    meta_data = JSONField("AliOSS文件元信息", blank=True, null=True, default={})
    url = models.CharField(verbose_name='访问地址')
    mime_type = models.CharField(verbose_name='MimeType', default="image/png")

    def __str__(self):
        return self.name if self.name else self.url

    def as_dict(self, keys=None, exclude_keys=None):
        return {
            'id': self.pk,
            'name': self.name,
            'mime_type': self.mime_type,
            'url': self.url,
        }
